﻿using System;
using System.Windows;
using UIExceptionHandler.Interfaces;

namespace UIExceptionHandlerWPF
{
    public partial class ErrorHandlerForm : Window, IErrorHandlerForm
    {
        public event Action OnSendButtonClick;
        public event Action OnShowErrorLinkClick;
        public event Action OnLogFileLinkClick;
        public event Action OnDebugButtonClick;

        public ErrorHandlerForm()
        {
            InitializeComponent();
            SubscribeEvents();
        }
        
        private void SubscribeEvents()
        {
            SendButton.Click += (sender, e) => OnSendButtonClick();
            DebugButton.Click += (sender, e) => OnDebugButtonClick();
            ShowErrorLinkLabel.MouseUp += (sender, e) => OnShowErrorLinkClick();
            LogFileLinkLabel.MouseUp += (sender, e) => OnLogFileLinkClick();
        }

        public void SetHeight(int height)
        {
            Height = height;
        }

        public string ExceptionInfoText
        {
            get { return ExceptionInfoTextBox.Text; }
            set { ExceptionInfoTextBox.Text = value; }
        }

        public string ExceptionDetailText
        {
            get { return DetailInfoTextBox.Text; }
            set { DetailInfoTextBox.Text = value; }
        }

        public string ReplyEmail
        {
            get { return ReplyEmailTextBox.Text; }
        }

        public void ShowExceptionInfoTextBox(bool isShow)
        {
            ExceptionInfoTextBox.Visibility = isShow ? Visibility.Visible : Visibility.Collapsed;
        }

        public void ShowInfoMessageBox(string text, string caption)
        {
            MessageBox.Show(text, caption, MessageBoxButton.OK, MessageBoxImage.Information);
        }

        public bool ShowQuestionDialog(string text, string caption)
        {
            return MessageBox.Show(text, caption, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes;
        }

        public void ShowViewDialog()
        {
            ShowDialog();
        }

        public void UpdateContactEmail(string contactEmail)
        {
            MessageLabel.Content += contactEmail + ". Thank you!";
        }
    }
}
